﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BoneImp {
	public class Animation {
		public string name;
		float duration {
			get {
				float LongestTime = 0;
				for (int i = 0; i < timelines.Count; i++) {
					if (LongestTime < timelines[i].GetDuration()) {
						LongestTime = timelines[i].GetDuration();
					}
				}
				return LongestTime;
			}
		}

		public List<Timeline> timelines;

		public Animation(string name) {
			this.name = name;
			//this.timelines.Count = timelineCount;
			this.timelines = new List<Timeline>(); //[timelines.Count];
		}

		public void apply(SkeletonBase skeleton, float time, bool loop) {
			if (loop && this.duration != 0) time = (float)((decimal)time % (decimal)this.duration);

			int i, n = this.timelines.Count;
			for (i = 0; i < n; ++i)
				this.timelines[i].apply(skeleton, time, 1);
		}

		public void mix(SkeletonBase skeleton, float time, bool loop, float alpha) {
			if (loop && this.duration != 0) time = (float)((decimal)time % (decimal)this.duration);

			int i, n = this.timelines.Count;
			for (i = 0; i < n; ++i)
				this.timelines[i].apply(skeleton, time, alpha);
		}
	}
}
